package com.weu.mapper;

import com.weu.bean.sysUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserMapper {
    /**
     * 查询用户名是否存在，若存在，不允许注册
     * 注解@Param(value) 若value与可变参数相同，注解可省略
     * 注解@Results  列名和字段名相同，注解可省略
     * @param
     * @return
     */
    @Select("SELECT u.user_name,u.user_password,u.user_role FROM ilmc_user u WHERE u.user_name=#{username}")
    @Results
            ({@Result(property = "userName",column = "user_name"),
                    @Result(property = "userPassword",column = "user_password"),
                    @Result(property = "userRole",column = "user_role")})
    sysUser findUserByName(String userName);
    /**
     * 注册
     */
    @Insert("INSERT INTO ilmc_user (user_name,user_password,user_email,user_role) VALUES (#{userName},#{userpassword},#{userEmail},'user')")
    //加入该注解可以保存对象后，查看对象插入id
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void register(sysUser user);

    @Select("SELECT u.user_name,u.user_password FROM ilmc_user u WHERE u.user_name=#{username}")
    sysUser login(String userName);
}
